<template>
  <div id="root">
    <div class="todo-container">
      <div class="todo-wrap">
        <TodoHeader></TodoHeader>
        <TodoMain></TodoMain>
        <TodoFooter></TodoFooter>
      </div>
    </div>
  </div>
</template>

<script>
import TodoHeader from "@/components/Todo-Vuex/Header";
import TodoMain from "@/components/Todo-Vuex/Main";
import TodoFooter from "@/components/Todo-Vuex/Footer";
export default {
  name: "TodoList",
  components: {
    TodoHeader,
    TodoMain,
    TodoFooter,
  },
  watch: {
    Todolist: {
      handler(nval, oval) {
        localStorage.setItem("TodolistVuex", JSON.stringify(nval));
      },
      deep: true,
    },
  },
  computed: {
    Todolist() {
      return this.$store.state.TODOLIST;
    },
  },
  mounted() {
    this.$store.dispatch(
      "MountTodo",
      JSON.parse(localStorage.getItem("TodolistVuex")) || [
        { id: 1, title: "吃饭", done: false },
        {
          id: 2,
          title: "打代码",
          done: true,
        },
      ]
    );
  },
};
</script>
<style scoped>
/*app*/
.todo-container {
  width: 600px;
  margin: 0 auto;
}
.todo-container .todo-wrap {
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
}
</style>